<?php
	/**
	 * @package AmpleHarvest
	 */
	use\ampleharvest\code;

	/**
	 * @brief This file is used to Run all notifications that are due.
	 *
	 * - Revision History
	 *  - 0.1
	 * 	 - <b>Date</b>: 24 MAR 2011
	 * 	 - <b>Author</b>: Randy Blancett
	 * 	  - Initial Version
	 *
	 * @author Randy Blancett
	 * @version 0.1
	 * @ingroup code script classes
	 */
	require_once dirname(dirname(dirname(__FILE__))) . '/config/cConfig.php';
	require_once dirname(dirname(dirname(__FILE__))) . '/classes/cStomp.php';
	require_once dirname(dirname(dirname(__FILE__))) . '/classes/cAmpleHarvestLog.php';
	require_once dirname(dirname(dirname(__FILE__))) . '/classes/search/solr/cSolr.php';

	$obj_Log = new \cAmpleHarvestLog();
	$obj_Stomp = new \cStomp();
	$obj_Solr = new cSolr(null, null, null);
	$this->output_Error("Using default solr instance -- clear_Solr");

	$obj_Stomp->subscribe(\cStomp::C_STR_QUEUE_SOLR_DELETE);

	$obj_Log->do_Log(cAmpleHarvestLog::C_STR_ACTION_DATA_INDEX_INFO,
		"Started Removeing old Index files",
		cAmpleHarvestLog::C_INT_LEVEL_INFO);

	while ($obj_Msg = $obj_Stomp->getMessage())
	{
		$obj_Log->do_Log(cAmpleHarvestLog::C_STR_ACTION_DATA_INDEX_INFO,
			"Pulled Old Index from Queue",
			cAmpleHarvestLog::C_INT_LEVEL_DEBUG);

		$obj_Data = json_decode($obj_Msg->body);

		print_r($obj_Data);

		try
		{
			$obj_Solr->deleteById($obj_Data->guid);
			$obj_Solr->commit();
			print("removed\n");
		}
		catch (Exception $e)
		{
			print("failed to remove\n");
			$obj_Log->do_Log(cAmpleHarvestLog::C_STR_ACTION_DATA_INDEX_ERROR,
				"Failed to remove " + $obj_Data->guid + "\n " + $e,
				cAmpleHarvestLog::C_INT_LEVEL_ERRORS);
		}

		$obj_Stomp->ackMessage($obj_Msg);
	}
	$obj_Solr->optimize();
	print("Finish\n");

	$obj_Log->do_Log(cAmpleHarvestLog::C_STR_ACTION_DATA_INDEX_INFO,
		"Finished Cleaning Index",
		cAmpleHarvestLog::C_INT_LEVEL_INFO);

?>
	